package com.boot.vo;

import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;

@Data
@Entity
@Table(name = "game_keyvalue")
public class KeyValue {
    private static final Long DEFAULT_LIVETIMES = 30000L;

    private KeyValue() {
    }

    /**
     * @param key
     * @param value
     * 设置一个keyvalue
     */
    public KeyValue(String key, String value) {
        this.key = key;
        this.value = value;
        this.liveTimes = DEFAULT_LIVETIMES;

        Date date = new Date();
        this.createTimes = date.getTime();
        this.createDate = date;
    }

    public KeyValue(String key) {
        this.key = key;
    }

    /**
     * @param key
     * @param value
     * @param liveTimes
     * 创建一个keyvalue，并设置他的他的存活时间
     */
    public KeyValue(String key, String value, Long liveTimes) {
        this.key = key;
        this.value = value;
        this.liveTimes = liveTimes;


        Date date = new Date();
        this.createTimes = date.getTime();
        this.createDate = date;
    }



    /**
     * 名称
     */
    @Id
    private String key;
    /**
     * value
     */
    private String value;
    /**
     * 时间戳
     */
    private Long times;
    /**
     * 创建时间戳
     */
    private Long createTimes;
    /**
     * 存活时间戳
     */
    private Long liveTimes;
    /**
     * 创建时间
     */
    private Date createDate;
    /**
     * 创建时间
     */
    private Date updateDate;
    /**
     * 备注
     */
    private String remark;
}
